package com.yc;

import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.MemoryId;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;


public class _11_AiServiceWithPersistentMemory {

    interface Assistant{
        @SystemMessage("你是一个java专家，你会回答用户的问题。")
        String chat( @MemoryId int memoryId, @UserMessage String message);
    }
    public static void main(String[] args) {
        PersistentChatMemoryStore persistentChatMemoryStore = new PersistentChatMemoryStore();
//创建一个chatMemoryProvider对象
        ChatMemoryProvider chatMemoryProvider = memoryId -> MessageWindowChatMemory.builder()
                .maxMessages(5)
                .chatMemoryStore(persistentChatMemoryStore)
                .id(memoryId)
                .build();
          String apiKey=System.getenv("DEEPSEEK_API_KEY");
         OpenAiChatModel model = OpenAiChatModel.builder()
                .apiKey(apiKey)
                .modelName("deepseek-chat")
                .baseUrl("https://api.deepseek.com")
                .logRequests(true)
                .logResponses(true)
                .build();

         Assistant assistant= AiServices.builder(Assistant.class)
                 .chatModel(model)
                 .chatMemoryProvider(chatMemoryProvider)
                 .build();
         assistant.chat(1," 我今年大三,想学习java,学习路线是什么");
         assistant.chat(2,"我是李四,我的专业是汉语言文学,想学习c,路线是什么");

    }

}

